package cn.zwx.multi_datasource_example.controller;

import cn.zwx.multi_datasource_example.mapper.db1.DataSynMapper;
import cn.zwx.multi_datasource_example.model.po.DataSyn;
import cn.zwx.multi_datasource_example.model.po.Order;
import cn.zwx.multi_datasource_example.service.db1.service.DataSynService;
import cn.zwx.multi_datasource_example.service.db2.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.UUID;

/**
 * @description:
 * @projectName:multi_datasource_example
 * @see:cn.zwx.multi_datasource_example.controller
 * @author:zhangwenxue
 * @createTime:2021/8/16 19:02
 * @version:1.0
 */
@RestController
public class HelloController {

    @Autowired
    OrderService orderService;
    @Autowired
    DataSynService dataSynService;


    @RequestMapping(value = "/test")
    @Transactional
    public String test(){
        Order order = new Order();
        order.setCreateTime(new Date());
        order.setUpdateTime(new Date());
        order.setDelFlag(0);
        order.setGoodsAmount(1000L);
        order.setGoodsId("123123");
        order.setGoodsName("达阿大声道");
        order.setGoodsNum(2);
        order.setOrderId("1231241433");
        order.setPayerId("123");
        order.setPayerName("XueXue");
        order.setOrderState(1);
        order.setTotalOrderAmount(2000L);
        order.setTotalPayAmount(1800L);
        order.setOrderId(UUID.randomUUID().toString().replace("-",""));
        orderService.insert(order);
//        int i = 10 / 0;
        DataSyn dataSyn = new DataSyn();
        dataSyn.setCreateTime(new Date());
        dataSyn.setUpdateTime(new Date());
        dataSyn.setDelFlag(Byte.valueOf("0"));
        dataSyn.setCreateName("XueXue");
        dataSyn.setKakaTopic("test_topic");
        dataSyn.setDestination("休息休息");
        dataSyn.setSubscribe("asdasd");
        dataSynService.insert(dataSyn);
        int i = 10 / 0;
        return "处理成功!!!";
    }
}
